package com.gxa.modules.property.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.modules.property.dto.RepairToAdd;
import com.gxa.modules.property.dto.RepairToUpdate;
import com.gxa.modules.property.dto.UserRepairToUpdate;
import com.gxa.modules.property.entity.Repair;
import com.gxa.modules.property.entity.RepairState;
import com.gxa.modules.property.entity.SecondItem;
import com.gxa.modules.property.mapper.RepairMapper;
import com.gxa.modules.property.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RepairServiceImpl extends ServiceImpl<RepairMapper, RepairState> implements RepairService {
    @Autowired
    private RepairMapper repairMapper;
    @Override
    public void add(RepairToAdd repairToAdd) {
        this.repairMapper.add(repairToAdd);
    }

    @Override
    public void delete(Integer id) {
        this.repairMapper.delete(id);
    }

    @Override
    public void update(RepairToUpdate repairToUpdate) {
        this.repairMapper.update(repairToUpdate);
    }

    @Override
    public PageInfo<Repair> queryRepair(Map<String, Object> params) {
        String page1 = (String) params.get("page");
        String limit1 = (String) params.get("limit");
        Integer page = Integer.valueOf(page1);
        Integer limit = Integer.valueOf(limit1);

        //条件查询
        String repairStateId = (String) params.get("repairStateId") ;
        String startTime = (String) params.get("startTime");
        String endTime = (String) params.get("endTime");
        String type = (String) params.get("type");
        String communityId = (String) params.get("communityId");


        PageHelper.startPage(page,limit);
        List<Repair> repairList = repairMapper.queryRepair(repairStateId,startTime,endTime,type,communityId
        );
        PageInfo<Repair> pageInfo = new PageInfo<>(repairList);

        return pageInfo;
    }

    @Override
    public List<RepairState> queryRepairState(Integer id) {
        return repairMapper.queryRepairState(id);
    }

    @Override
    public void userUpdate(UserRepairToUpdate userRepairToUpdate) {
        this.repairMapper.userUpdate(userRepairToUpdate);
    }

    @Override
    public List<SecondItem> queryByName(String secondItemType) {
        return repairMapper.queryByName(secondItemType);
    }
}
